import 'package:flutter/material.dart';

/// UI组件库颜色令牌
/// 基于Material Design 3动态颜色系统
class UIColors {
  // 基础色彩 - Material 3 蓝色系动态颜色
  static const ColorScheme lightScheme = ColorScheme.light(
    // 主色调 - 蓝色系
    primary: Color(0xFF1976D2),              // Material Blue 700
    onPrimary: Color(0xFFFFFFFF),            // 白色文本
    primaryContainer: Color(0xFFE3F2FD),     // Material Blue 50
    onPrimaryContainer: Color(0xFF0D47A1),   // Material Blue 900
    
    // 次色调 - 蓝灰色系
    secondary: Color(0xFF455A64),            // Blue Grey 700
    onSecondary: Color(0xFFFFFFFF),          // 白色文本
    secondaryContainer: Color(0xFFECEFF1),   // Blue Grey 50
    onSecondaryContainer: Color(0xFF263238), // Blue Grey 900
    
    // 第三色调 - 青色系
    tertiary: Color(0xFF0097A7),             // Cyan 700
    onTertiary: Color(0xFFFFFFFF),           // 白色文本
    tertiaryContainer: Color(0xFFE0F7FA),    // Cyan 50
    onTertiaryContainer: Color(0xFF006064),  // Cyan 900
    
    // 错误色
    error: Color(0xFFD32F2F),                // Red 700
    onError: Color(0xFFFFFFFF),              // 白色文本
    errorContainer: Color(0xFFFFEBEE),       // Red 50
    onErrorContainer: Color(0xFFB71C1C),     // Red 900
    
    // 表面色
    surface: Color(0xFFFAFAFA),              // Grey 50
    onSurface: Color(0xFF212121),            // Grey 900
    surfaceVariant: Color(0xFFE8EAF6),       // Indigo 50
    onSurfaceVariant: Color(0xFF3F51B5),     // Indigo 500
    
    // 轮廓色
    outline: Color(0xFF9E9E9E),              // Grey 500
    outlineVariant: Color(0xFFE0E0E0),       // Grey 300
    
    // 系统色
    shadow: Color(0xFF000000),               // 阴影色
    scrim: Color(0xFF000000),                // 遮罩色
    
    // 反转色
    inverseSurface: Color(0xFF424242),       // Grey 800
    onInverseSurface: Color(0xFFFFFFFF),     // 白色
    inversePrimary: Color(0xFF90CAF9),       // Light Blue 200
    
    // 背景色
    background: Color(0xFFFFFFFF),           // 纯白背景
    onBackground: Color(0xFF212121),         // Grey 900
  );

  static const ColorScheme darkScheme = ColorScheme.dark(
    // 主色调 - 蓝色系深色
    primary: Color(0xFF90CAF9),              // Light Blue 200
    onPrimary: Color(0xFF0D47A1),            // Blue 900
    primaryContainer: Color(0xFF1565C0),     // Blue 800
    onPrimaryContainer: Color(0xFFBBDEFB),   // Light Blue 100
    
    // 次色调 - 蓝灰色系深色
    secondary: Color(0xFF90A4AE),            // Blue Grey 300
    onSecondary: Color(0xFF263238),          // Blue Grey 900
    secondaryContainer: Color(0xFF37474F),   // Blue Grey 800
    onSecondaryContainer: Color(0xFFCFD8DC), // Blue Grey 100
    
    // 第三色调 - 青色系深色
    tertiary: Color(0xFF4DD0E1),             // Cyan 300
    onTertiary: Color(0xFF006064),           // Cyan 900
    tertiaryContainer: Color(0xFF00838F),    // Cyan 800
    onTertiaryContainer: Color(0xFFB2EBF2),  // Cyan 100
    
    // 错误色
    error: Color(0xFFEF5350),                // Red 400
    onError: Color(0xFFB71C1C),              // Red 900
    errorContainer: Color(0xFFC62828),       // Red 800
    onErrorContainer: Color(0xFFFFCDD2),     // Red 100
    
    // 表面色
    surface: Color(0xFF121212),              // 深色表面
    onSurface: Color(0xFFE0E0E0),            // Grey 300
    surfaceVariant: Color(0xFF303F9F),       // Indigo 700
    onSurfaceVariant: Color(0xFFC5CAE9),     // Indigo 100
    
    // 轮廓色
    outline: Color(0xFF757575),              // Grey 600
    outlineVariant: Color(0xFF424242),       // Grey 800
    
    // 系统色
    shadow: Color(0xFF000000),               // 阴影色
    scrim: Color(0xFF000000),                // 遮罩色
    
    // 反转色
    inverseSurface: Color(0xFFFAFAFA),       // Grey 50
    onInverseSurface: Color(0xFF212121),     // Grey 900
    inversePrimary: Color(0xFF1976D2),       // Blue 700
    
    // 背景色
    background: Color(0xFF0A0A0A),           // 深黑背景
    onBackground: Color(0xFFE0E0E0),         // Grey 300
  );

  // 语义化颜色 - 蓝色系兼容
  static const Color success = Color(0xFF388E3C);        // Green 700
  static const Color successContainer = Color(0xFFE8F5E8); // Green 50
  static const Color onSuccessContainer = Color(0xFF1B5E20); // Green 900

  static const Color warning = Color(0xFFF57C00);        // Orange 700
  static const Color warningContainer = Color(0xFFFFF3E0); // Orange 50
  static const Color onWarningContainer = Color(0xFFE65100); // Orange 900

  static const Color info = Color(0xFF1976D2);           // Blue 700 (与主色调一致)
  static const Color infoContainer = Color(0xFFE3F2FD);   // Blue 50
  static const Color onInfoContainer = Color(0xFF0D47A1); // Blue 900

  // 组件状态颜色 - 基于蓝色系
  static const Color loadingPrimary = Color(0xFF1976D2);   // Blue 700
  static const Color loadingSecondary = Color(0xFF455A64); // Blue Grey 700
  static const Color skeletonBase = Color(0xFFE0E0E0);     // Grey 300
  static const Color skeletonHighlight = Color(0xFFF5F5F5); // Grey 100
  static const Color skeletonBaseDark = Color(0xFF424242);  // Grey 800
  static const Color skeletonHighlightDark = Color(0xFF616161); // Grey 700

  // 分享类型颜色 - 蓝色系为主
  static const Color textShare = Color(0xFF3F51B5);       // Indigo 500
  static const Color urlShare = Color(0xFF2196F3);        // Blue 500
  static const Color imageShare = Color(0xFF00BCD4);      // Cyan 500
  static const Color fileShare = Color(0xFF607D8B);       // Blue Grey 500
  static const Color videoShare = Color(0xFF9C27B0);      // Purple 500

  // 按钮状态颜色 - 蓝色系兼容
  static const Color buttonSuccess = Color(0xFF4CAF50);   // Green 500
  static const Color buttonError = Color(0xFFF44336);     // Red 500
  static const Color buttonLoading = Color(0xFF1976D2);   // Blue 700

  // 获取当前颜色方案
  static ColorScheme getColorScheme(Brightness brightness) {
    return brightness == Brightness.light ? lightScheme : darkScheme;
  }

  // 获取骨架屏颜色
  static Color getSkeletonBase(Brightness brightness) {
    return brightness == Brightness.light ? skeletonBase : skeletonBaseDark;
  }

  static Color getSkeletonHighlight(Brightness brightness) {
    return brightness == Brightness.light ? skeletonHighlight : skeletonHighlightDark;
  }

  // 蓝色系扩展调色板
  static const Color blue50 = Color(0xFFE3F2FD);    // Blue 50
  static const Color blue100 = Color(0xFFBBDEFB);   // Blue 100
  static const Color blue200 = Color(0xFF90CAF9);   // Blue 200
  static const Color blue300 = Color(0xFF64B5F6);   // Blue 300
  static const Color blue400 = Color(0xFF42A5F5);   // Blue 400
  static const Color blue500 = Color(0xFF2196F3);   // Blue 500
  static const Color blue600 = Color(0xFF1E88E5);   // Blue 600
  static const Color blue700 = Color(0xFF1976D2);   // Blue 700 (主色调)
  static const Color blue800 = Color(0xFF1565C0);   // Blue 800
  static const Color blue900 = Color(0xFF0D47A1);   // Blue 900

  // 蓝灰色系扩展调色板
  static const Color blueGrey50 = Color(0xFFECEFF1);   // Blue Grey 50
  static const Color blueGrey100 = Color(0xFFCFD8DC);  // Blue Grey 100
  static const Color blueGrey200 = Color(0xFFB0BEC5);  // Blue Grey 200
  static const Color blueGrey300 = Color(0xFF90A4AE);  // Blue Grey 300
  static const Color blueGrey400 = Color(0xFF78909C);  // Blue Grey 400
  static const Color blueGrey500 = Color(0xFF607D8B);  // Blue Grey 500
  static const Color blueGrey600 = Color(0xFF546E7A);  // Blue Grey 600
  static const Color blueGrey700 = Color(0xFF455A64);  // Blue Grey 700 (次色调)
  static const Color blueGrey800 = Color(0xFF37474F);  // Blue Grey 800
  static const Color blueGrey900 = Color(0xFF263238);  // Blue Grey 900

  // 青色系扩展调色板
  static const Color cyan50 = Color(0xFFE0F7FA);    // Cyan 50
  static const Color cyan100 = Color(0xFFB2EBF2);   // Cyan 100
  static const Color cyan200 = Color(0xFF80DEEA);   // Cyan 200
  static const Color cyan300 = Color(0xFF4DD0E1);   // Cyan 300
  static const Color cyan400 = Color(0xFF26C6DA);   // Cyan 400
  static const Color cyan500 = Color(0xFF00BCD4);   // Cyan 500
  static const Color cyan600 = Color(0xFF00ACC1);   // Cyan 600
  static const Color cyan700 = Color(0xFF0097A7);   // Cyan 700 (第三色调)
  static const Color cyan800 = Color(0xFF00838F);   // Cyan 800
  static const Color cyan900 = Color(0xFF006064);   // Cyan 900

  // 获取蓝色系渐变
  static LinearGradient get primaryGradient => const LinearGradient(
    colors: [blue400, blue700],
    begin: Alignment.topLeft,
    end: Alignment.bottomRight,
  );

  static LinearGradient get secondaryGradient => const LinearGradient(
    colors: [blueGrey300, blueGrey700],
    begin: Alignment.topLeft,
    end: Alignment.bottomRight,
  );

  static LinearGradient get tertiaryGradient => const LinearGradient(
    colors: [cyan300, cyan700],
    begin: Alignment.topLeft,
    end: Alignment.bottomRight,
  );

  // 获取表面渐变 (深色到浅色)
  static LinearGradient getSurfaceGradient(Brightness brightness) {
    if (brightness == Brightness.light) {
      return const LinearGradient(
        colors: [Color(0xFFFFFFFF), Color(0xFFFAFAFA)],
        begin: Alignment.topCenter,
        end: Alignment.bottomCenter,
      );
    } else {
      return const LinearGradient(
        colors: [Color(0xFF1A1A1A), Color(0xFF0A0A0A)],
        begin: Alignment.topCenter,
        end: Alignment.bottomCenter,
      );
    }
  }

  // 获取强调色 (用于突出显示)
  static Color getAccentColor(Brightness brightness) {
    return brightness == Brightness.light ? blue600 : blue300;
  }

  // 获取禁用状态颜色
  static Color getDisabledColor(Brightness brightness) {
    return brightness == Brightness.light 
        ? const Color(0xFF9E9E9E) 
        : const Color(0xFF616161);
  }

  // 获取分割线颜色
  static Color getDividerColor(Brightness brightness) {
    return brightness == Brightness.light 
        ? const Color(0xFFE0E0E0) 
        : const Color(0xFF424242);
  }

  // 获取悬停状态颜色
  static Color getHoverColor(Color baseColor, {double opacity = 0.04}) {
    return baseColor.withOpacity(opacity);
  }

  // 获取焦点状态颜色
  static Color getFocusColor(Color baseColor, {double opacity = 0.12}) {
    return baseColor.withOpacity(opacity);
  }

  // 获取按下状态颜色
  static Color getPressedColor(Color baseColor, {double opacity = 0.16}) {
    return baseColor.withOpacity(opacity);
  }

  // 便捷访问属性 - 基于蓝色系主题
  static Color get primaryColor => blue700;        // Blue 700
  static Color get onPrimary => lightScheme.onPrimary;
  static Color get primaryContainer => blue50;     // Blue 50
  static Color get onPrimaryContainer => blue900;  // Blue 900
  
  static Color get secondary => blueGrey700;       // Blue Grey 700
  static Color get onSecondary => lightScheme.onSecondary;
  static Color get secondaryContainer => blueGrey50; // Blue Grey 50
  static Color get onSecondaryContainer => blueGrey900; // Blue Grey 900
  
  static Color get tertiary => cyan700;            // Cyan 700
  static Color get onTertiary => lightScheme.onTertiary;
  static Color get tertiaryContainer => cyan50;    // Cyan 50
  static Color get onTertiaryContainer => cyan900; // Cyan 900
  
  static Color get surface => lightScheme.surface;
  static Color get onSurface => lightScheme.onSurface;
  static Color get background => lightScheme.background;
  static Color get onBackground => lightScheme.onBackground;
  static Color get errorColor => lightScheme.error;
  static Color get onError => lightScheme.onError;
  static Color get surfaceVariant => lightScheme.surfaceVariant;
  static Color get onSurfaceVariant => lightScheme.onSurfaceVariant;
  static Color get outline => lightScheme.outline;
}